﻿using System;
using System.Collections.Generic;
using DWEIP.Models.Sys;
using DataWin.Core.Model;
using DataWin.Core.Util;

namespace DWEIP.BLL.Sys
{
    public partial class SysStructBLL : BasicBLL
    {
        public List<SysStructModel> GetList(string parentId)
        {
            if (BLLSession == null)
            {
                return null;
            }

            //目前parentId 用不到

            BLLSession.BeginTransaction();
            Table _tsm07 = new Table("tsm07");
            _tsm07.SQL.Value = @"
SELECT tsm07.* FROM tsm07 where sg01=@sg01 AND sg020=@sg020";
            _tsm07.Params.Clear();
            _tsm07.Params.Add("sg01", new Data("G"));
            _tsm07.Params.Add("sg020", new Data("1"));//先不和controller连接
            BLLSession.Load(_tsm07);
            BLLSession.Commit();

            List<SysStructModel> structList = new List<SysStructModel>();
            if (_tsm07.Count > 0)
            {
                int sortNum = 1;
                foreach (IRow Row in _tsm07)
                {
                    SysStructModel structModel = new SysStructModel();
                    structModel.Id = Row["sg021"].AsString;
                    structModel.Name = Row["sg03"].AsString;
                    structModel.ParentId = "root";
                    structModel.Sort = sortNum++;
                    structModel.Enable = true;
                    structModel.CreateTime = DateTime.Now;
                    structModel.Higher = "0";
                    structModel.Remark = "";
                    structModel.Type = "group";
                    structList.Add(structModel);
                }
            }
            else
            {
                SysStructModel structModel = new SysStructModel();
                structModel.Id = "ROOT";
                structModel.Name = "ALL";
                structModel.ParentId = "root";
                structModel.Sort = 1;
                structModel.Enable = true;
                structModel.CreateTime = DateTime.Now;
                structModel.Higher = "0";
                structModel.Remark = "";
                structModel.Type = "group";
                structList.Add(structModel);
            }

            return structList;
        }
    }
}
